package com.czxy.enterprise.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.czxy.domain.TbWelfare;
import com.czxy.enterprise.service.WelfareService;
import com.czxy.findjob.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 福利表 前端控制器
 * </p>
 *
 * @author xuewen
 * @since 2022-01-25
 */
@RestController
@RequestMapping("/welfare")
public class WelfareController {
    @Autowired
    private WelfareService welfareService;
    @GetMapping("/findAll")
    public BaseResult findAll(){
        List<TbWelfare> list = welfareService.list();
        return BaseResult.ok("查询成功",list);
    }
    @GetMapping("/condition/{current}/{size}")
    public BaseResult condition(@PathVariable("current") Integer current,@PathVariable("size") Integer size){
        Page page = new Page(current,size);
        welfareService.page(page);
        return BaseResult.ok("查询成成功",page);
    }
    @GetMapping("/findById/{id}")
    public BaseResult findById(@PathVariable("id") Integer id){
        return BaseResult.ok("查询成功",welfareService.getById(id));
    }
    @DeleteMapping("/delById/{id}")
    public BaseResult del(@PathVariable("id") Integer id){
        boolean b = welfareService.removeById(id);
        if (b){
            return BaseResult.ok("删除成功");
        }else {
            return BaseResult.error("删除失败");
        }

    }
    @PostMapping("/saveOrUpdate")
    public BaseResult saveOrUpdate(@RequestBody TbWelfare tbWelfare){
        boolean b = welfareService.saveOrUpdate(tbWelfare);
        if (b){
            return BaseResult.ok("保存成功");
        }else {
            return BaseResult.error("保存失败");
        }
    }

}

